package graphics.view2D;

import graphics.interfaces.ICoordinateConverter2D;
import model.Square;

public class Coord2D implements ICoordinateConverter2D {
	
	/*
	 * Pattern Singleton
	 */
    private static Coord2D instance;
    public static Coord2D getInstance() {
        if (null == instance) {
            instance = new Coord2D();
        }
        return instance;
    }
	 
    public int getXFromSquare(Square square){
		return square.getCol() * 60;
	}

	public int getYFromSquare(Square square){
		return square.getRow() * 60;
	}
	
	/**
	 * Get the column on the board from a location on he screen
	 * 
	 * @param x
	 *            X location on the screen
	 * @param y
	 *            Y location on the screen
	 * @return the column
	 */
	public int getColFromXY(float x, float y) {
		return Math.min((int)(x/60), 7);
	}

	/**
	 * Get the row on the board from a location on he screen
	 * 
	 * @param x
	 *            X location on the screen
	 * @param y
	 *            Y location on the screen
	 * @return the row
	 */
	public int getRowFromXY(float x, float y) {
		return Math.min(Math.abs((int)((y-480)/60)), 7);
	}
}
